package com.example.anju.mapper;

import java.util.List;

import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import com.example.anju.entity.House;

@Mapper
@Repository
public interface HouseMapper {
	// 根据house_user_id搜索房源
	@Select("SELECT * FROM house WHERE house_user_id=#{house_user_id}")
	List<House> findHouseByUserId(@Param("house_user_id") int house_user_id);

	// 根据house_id搜索房源
	@Select("SELECT * FROM house WHERE house_id=#{house_id}")
	List<House> findHouseByHouseId(@Param("house_id") int house_id);

	// 发布房源
	@Insert("INSERT INTO house VALUES(#{house_id},#{house_user_id},#{location},#{address},#{house_rent},#{home_type},#{time_type},#{renovation},#{other},#{area},#{house_images})")
	@Options(useGeneratedKeys = true, keyProperty = "house_id", keyColumn = "house_id")
	void publishHouse(House house);

	// 修改房源
	@Insert("UPDATE house SET location=#{location},address=#{address},house_rent=#{house_rent},home_type=#{home_type},time_type=#{time_type} ,renovation=#{renovation},other=#{other},area=#{area} WHERE house_id=#{house_id}")
	void changeHouseByHouseId(House house);

	// 根据location搜索房源
	@Select("SELECT * FROM house WHERE location=#{location}")
	List<House> findHouseByLocation(@Param("location") String location);

	// 根据address搜索房源
	@Select("SELECT * FROM house WHERE address LIKE '%${address}%'")
	List<House> findHouseByAddress(@Param("address") String address);

	// 根据time_type搜索房源
	@Select("SELECT * FROM house WHERE time_type=#{time_type}")
	List<House> findHouseByTimeType(@Param("time_type") String time_type);

	// 根据home_type搜索房源
	@Select("SELECT * FROM house WHERE home_type=#{home_type}")
	List<House> findHouseByHomeType(@Param("home_type") String home_type);

//	// 根据house_rent搜索房源
//	@Select("SELECT * FROM house WHERE #{house_rent} between min_rent AND max_rent")
//	List<House> findHouseByHouseRent(@Param("house_rent") int house_rent, @Param("min_rent") int min_rent,
//			@Param("max_rent") int max_rent);

}
